<html>
<head><meta charset="utf-8"><title>upstreaming LLVM patch for __rust_ alloc functions · t-compiler · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/index.html">t-compiler</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/upstreaming.20LLVM.20patch.20for.20__rust_.20alloc.20functions.html">upstreaming LLVM patch for __rust_ alloc functions</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="247370657"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/upstreaming%20LLVM%20patch%20for%20__rust_%20alloc%20functions/near/247370657" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> durin42 <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/upstreaming.20LLVM.20patch.20for.20__rust_.20alloc.20functions.html#247370657">(Jul 27 2021 at 18:17)</a>:</h4>
<p>I'm back on this. Is there a reason to not send that patch upstream? There's plenty of caselaw for non-C++ stuff in LLVM (eg Swift) and it seems like it might make sense to just land this patch there. I'm happy to try and have that discussion with LLVM folks if there's not a compelling reason to keep it Rust-local.</p>



<a name="247426192"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/upstreaming%20LLVM%20patch%20for%20__rust_%20alloc%20functions/near/247426192" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/upstreaming.20LLVM.20patch.20for.20__rust_.20alloc.20functions.html#247426192">(Jul 28 2021 at 06:28)</a>:</h4>
<p>LLVM hardcoding those symbols would effectively mean they're stable and we can't fix them</p>



<a name="247426209"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/upstreaming%20LLVM%20patch%20for%20__rust_%20alloc%20functions/near/247426209" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/upstreaming.20LLVM.20patch.20for.20__rust_.20alloc.20functions.html#247426209">(Jul 28 2021 at 06:28)</a>:</h4>
<p>I've been meaning to switch them for a while to something more "mangled" to avoid them looking like C symbols</p>



<a name="247426300"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/upstreaming%20LLVM%20patch%20for%20__rust_%20alloc%20functions/near/247426300" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/upstreaming.20LLVM.20patch.20for.20__rust_.20alloc.20functions.html#247426300">(Jul 28 2021 at 06:30)</a>:</h4>
<p><span class="user-mention" data-user-id="316805">@durin42</span> also, as the PR linked above (<a href="https://github.com/rust-lang/llvm-project/pull/89">https://github.com/rust-lang/llvm-project/pull/89</a>) makes it clear, <em>the signatures have changed</em>, so we'd also need some kind of versioning in the symbol name</p>



<a name="247426389"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/upstreaming%20LLVM%20patch%20for%20__rust_%20alloc%20functions/near/247426389" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/upstreaming.20LLVM.20patch.20for.20__rust_.20alloc.20functions.html#247426389">(Jul 28 2021 at 06:32)</a>:</h4>
<p>it would be useful to be able to use attributes or something to pass this information to LLVM, so we don't need LLVM to know about Rust symbols <em>at all</em></p>



<a name="247426485"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/upstreaming%20LLVM%20patch%20for%20__rust_%20alloc%20functions/near/247426485" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/upstreaming.20LLVM.20patch.20for.20__rust_.20alloc.20functions.html#247426485">(Jul 28 2021 at 06:35)</a>:</h4>
<p>maybe metadata connecting alloc/realloc/free functions together</p>



<a name="247431351"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/upstreaming%20LLVM%20patch%20for%20__rust_%20alloc%20functions/near/247431351" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/upstreaming.20LLVM.20patch.20for.20__rust_.20alloc.20functions.html#247431351">(Jul 28 2021 at 07:57)</a>:</h4>
<p>The signatures are unlikely to change nowadays as <code>GlobalAlloc</code> has been stabilized and the <code>__rust_*</code> allocator methods have a 1-to-1 correspondence with <code>GlobalAlloc</code> methods. They only happen to expand <code>Layout</code> into a separate size and align argument.</p>



<a name="247434689"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/upstreaming%20LLVM%20patch%20for%20__rust_%20alloc%20functions/near/247434689" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/upstreaming.20LLVM.20patch.20for.20__rust_.20alloc.20functions.html#247434689">(Jul 28 2021 at 08:40)</a>:</h4>
<p>I just don't want to bake any assumptions about <em>unstable Rust std internals</em> into LLVM</p>



<a name="247434752"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/upstreaming%20LLVM%20patch%20for%20__rust_%20alloc%20functions/near/247434752" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/upstreaming.20LLVM.20patch.20for.20__rust_.20alloc.20functions.html#247434752">(Jul 28 2021 at 08:41)</a>:</h4>
<p>sure, the API wrapping those symbols might be stable, but the linking/call ABI isn't</p>



<a name="247434781"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/upstreaming%20LLVM%20patch%20for%20__rust_%20alloc%20functions/near/247434781" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/upstreaming.20LLVM.20patch.20for.20__rust_.20alloc.20functions.html#247434781">(Jul 28 2021 at 08:41)</a>:</h4>
<p>in fact it's probably broken if you try to mix multiple Rust versions into one process...</p>



<a name="247435193"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/upstreaming%20LLVM%20patch%20for%20__rust_%20alloc%20functions/near/247435193" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/upstreaming.20LLVM.20patch.20for.20__rust_.20alloc.20functions.html#247435193">(Jul 28 2021 at 08:47)</a>:</h4>
<p>The ABI is set to "C", so it doesn't change unless the allocator shim is explicitly changed.</p>



<a name="247435798"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/upstreaming%20LLVM%20patch%20for%20__rust_%20alloc%20functions/near/247435798" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/upstreaming.20LLVM.20patch.20for.20__rust_.20alloc.20functions.html#247435798">(Jul 28 2021 at 08:54)</a>:</h4>
<p><span class="user-mention silent" data-user-id="119009">eddyb</span> <a href="#narrow/stream/131828-t-compiler/topic/upstreaming.20LLVM.20patch.20recognizing.20.60__rust_*.60.20allocator.20.20.2E.2E.2E/near/247434689">said</a>:</p>
<blockquote>
<p>I just don't want to bake any assumptions about <em>unstable Rust std internals</em> into LLVM</p>
</blockquote>
<p>If anything I would like it to be stabilized. That would allow C code to use the rust allocator to say allocate a <code>Box</code> or <code>Vec</code> without requiring everyone to write wrappers in rust. For example <code>cxx</code> has a lot of rust wrappers like <a href="https://github.com/dtolnay/cxx/blob/9c1737feff7208cd4825984614beaf09a27aefcf/src/symbols/rust_vec.rs#L15-L56">https://github.com/dtolnay/cxx/blob/9c1737feff7208cd4825984614beaf09a27aefcf/src/symbols/rust_vec.rs#L15-L56</a> that are called from C++ when trying to do anything with a <code>rust::Vec&lt;T&gt;</code> which is a C++ type that can be converted from and to a rust <code>Vec&lt;T&gt;</code> without reallocating.</p>



<a name="247435806"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/upstreaming%20LLVM%20patch%20for%20__rust_%20alloc%20functions/near/247435806" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/upstreaming.20LLVM.20patch.20for.20__rust_.20alloc.20functions.html#247435806">(Jul 28 2021 at 08:54)</a>:</h4>
<p>that just makes me want to try to hide the symbols more</p>



<a name="247435832"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/upstreaming%20LLVM%20patch%20for%20__rust_%20alloc%20functions/near/247435832" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/upstreaming.20LLVM.20patch.20for.20__rust_.20alloc.20functions.html#247435832">(Jul 28 2021 at 08:55)</a>:</h4>
<p>they are a way for two crates to communicate. they <em>should never</em> be accessible through other means</p>



<a name="247435869"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/upstreaming%20LLVM%20patch%20for%20__rust_%20alloc%20functions/near/247435869" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/upstreaming.20LLVM.20patch.20for.20__rust_.20alloc.20functions.html#247435869">(Jul 28 2021 at 08:55)</a>:</h4>
<p>also, it's not really about what changes we make today, that I'm worried about, but about baking in something that we might later find a reason to want to change</p>



<a name="247435870"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/upstreaming%20LLVM%20patch%20for%20__rust_%20alloc%20functions/near/247435870" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/upstreaming.20LLVM.20patch.20for.20__rust_.20alloc.20functions.html#247435870">(Jul 28 2021 at 08:55)</a>:</h4>
<p>Why would you want to change it? There are literally zero alternative implementation methods. <code>__rust_*</code> is effectively exposed to stable as <code>alloc::Global</code>.</p>



<a name="247436003"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/upstreaming%20LLVM%20patch%20for%20__rust_%20alloc%20functions/near/247436003" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/upstreaming.20LLVM.20patch.20for.20__rust_.20alloc.20functions.html#247436003">(Jul 28 2021 at 08:57)</a>:</h4>
<p><span class="user-mention" data-user-id="133247">@bjorn3</span> currently if you try to use custom global allocators from multiple <em>independently compiled</em> Rust <code>cdylib</code>s, aren't they broken? if C can see the symbol, doesn't that mean one of the allocators will be ignored?</p>



<a name="247436071"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/upstreaming%20LLVM%20patch%20for%20__rust_%20alloc%20functions/near/247436071" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/upstreaming.20LLVM.20patch.20for.20__rust_.20alloc.20functions.html#247436071">(Jul 28 2021 at 08:58)</a>:</h4>
<p>that's, for example, something that should IMO be fixed</p>



<a name="247436082"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/upstreaming%20LLVM%20patch%20for%20__rust_%20alloc%20functions/near/247436082" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/upstreaming.20LLVM.20patch.20for.20__rust_.20alloc.20functions.html#247436082">(Jul 28 2021 at 08:58)</a>:</h4>
<p>One allocator has to be ignored either way. Imagine two cdylibs depend on the same <code>libstd.so</code>. Which allocator should <code>libstd.so</code> use?</p>



<a name="247436107"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/upstreaming%20LLVM%20patch%20for%20__rust_%20alloc%20functions/near/247436107" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/upstreaming.20LLVM.20patch.20for.20__rust_.20alloc.20functions.html#247436107">(Jul 28 2021 at 08:58)</a>:</h4>
<p>my point is a situation in which <em>they don't</em></p>



<a name="247436110"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/upstreaming%20LLVM%20patch%20for%20__rust_%20alloc%20functions/near/247436110" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/upstreaming.20LLVM.20patch.20for.20__rust_.20alloc.20functions.html#247436110">(Jul 28 2021 at 08:58)</a>:</h4>
<p>sorry, I forgot to say "multiple versions of Rust" too</p>



<a name="247436135"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/upstreaming%20LLVM%20patch%20for%20__rust_%20alloc%20functions/near/247436135" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/upstreaming.20LLVM.20patch.20for.20__rust_.20alloc.20functions.html#247436135">(Jul 28 2021 at 08:59)</a>:</h4>
<p>(or <code>-Z build-std</code> I guess)</p>



<a name="247436181"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/upstreaming%20LLVM%20patch%20for%20__rust_%20alloc%20functions/near/247436181" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/upstreaming.20LLVM.20patch.20for.20__rust_.20alloc.20functions.html#247436181">(Jul 28 2021 at 08:59)</a>:</h4>
<p>If <code>__rust_*</code> becomes stabilized, there is no problem with using the same allocator from multiple versions of rust.</p>



<a name="247436255"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/upstreaming%20LLVM%20patch%20for%20__rust_%20alloc%20functions/near/247436255" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/upstreaming.20LLVM.20patch.20for.20__rust_.20alloc.20functions.html#247436255">(Jul 28 2021 at 09:00)</a>:</h4>
<p>I think panicking is similarly broken, and even worse since the ABI is nowhere near as unchanging</p>



<a name="247436328"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/upstreaming%20LLVM%20patch%20for%20__rust_%20alloc%20functions/near/247436328" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/upstreaming.20LLVM.20patch.20for.20__rust_.20alloc.20functions.html#247436328">(Jul 28 2021 at 09:00)</a>:</h4>
<p>Probably.</p>



<a name="247436361"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/upstreaming%20LLVM%20patch%20for%20__rust_%20alloc%20functions/near/247436361" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/upstreaming.20LLVM.20patch.20for.20__rust_.20alloc.20functions.html#247436361">(Jul 28 2021 at 09:00)</a>:</h4>
<p>anyway, I think stabilizing any of these <em>implementation details</em> requires an RFC, and until such a thing gets accepted, I'd rather make these "oh we just hardcoded some symbol names" things more hidden and less predictable</p>



<a name="247436385"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/upstreaming%20LLVM%20patch%20for%20__rust_%20alloc%20functions/near/247436385" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/upstreaming.20LLVM.20patch.20for.20__rust_.20alloc.20functions.html#247436385">(Jul 28 2021 at 09:01)</a>:</h4>
<p>Add the rustc version to the symbol name?</p>



<a name="247436481"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/upstreaming%20LLVM%20patch%20for%20__rust_%20alloc%20functions/near/247436481" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/upstreaming.20LLVM.20patch.20for.20__rust_.20alloc.20functions.html#247436481">(Jul 28 2021 at 09:02)</a>:</h4>
<p>if we can avoid LLVM hardcoding them, then we can probably fully mangle them (since the crate defining these symbols always depends on the crate declaring them <em>anyway</em>, so they can come from the latter)</p>



<a name="247436517"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/upstreaming%20LLVM%20patch%20for%20__rust_%20alloc%20functions/near/247436517" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/upstreaming.20LLVM.20patch.20for.20__rust_.20alloc.20functions.html#247436517">(Jul 28 2021 at 09:03)</a>:</h4>
<p>i.e. weak lang items would require exactly one declaration and one definition, and the definition cannot be supplied unless the declaration already exists in an upstream crate</p>



<a name="247436538"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/upstreaming%20LLVM%20patch%20for%20__rust_%20alloc%20functions/near/247436538" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/upstreaming.20LLVM.20patch.20for.20__rust_.20alloc.20functions.html#247436538">(Jul 28 2021 at 09:03)</a>:</h4>
<p>then, you just use the declaration's mangling as the symbol name</p>



<a name="247436663"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/upstreaming%20LLVM%20patch%20for%20__rust_%20alloc%20functions/near/247436663" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/upstreaming.20LLVM.20patch.20for.20__rust_.20alloc.20functions.html#247436663">(Jul 28 2021 at 09:05)</a>:</h4>
<p>this could potentially allow e.g. incompatible panic runtimes from separate <code>-Z build-std</code>, to avoid interfering with eachother in the same process (but Cargo may make this non-trivial)</p>



<a name="247436696"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/upstreaming%20LLVM%20patch%20for%20__rust_%20alloc%20functions/near/247436696" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/upstreaming.20LLVM.20patch.20for.20__rust_.20alloc.20functions.html#247436696">(Jul 28 2021 at 09:05)</a>:</h4>
<p>That would require renaming the personality function too I think.</p>



<a name="247436797"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/upstreaming%20LLVM%20patch%20for%20__rust_%20alloc%20functions/near/247436797" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/upstreaming.20LLVM.20patch.20for.20__rust_.20alloc.20functions.html#247436797">(Jul 28 2021 at 09:06)</a>:</h4>
<p>It is currently hard coded as <code>rust_eh_personality</code>. Not even with an <code>__</code> prefix.</p>



<a name="247436810"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/upstreaming%20LLVM%20patch%20for%20__rust_%20alloc%20functions/near/247436810" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/upstreaming.20LLVM.20patch.20for.20__rust_.20alloc.20functions.html#247436810">(Jul 28 2021 at 09:07)</a>:</h4>
<p><em>yikes</em></p>



<a name="247437382"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/upstreaming%20LLVM%20patch%20for%20__rust_%20alloc%20functions/near/247437382" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/upstreaming.20LLVM.20patch.20for.20__rust_.20alloc.20functions.html#247437382">(Jul 28 2021 at 09:14)</a>:</h4>
<p>This is the full list of unmangled symbols exported by a rust dylib:</p>
<ul>
<li>__rust_alloc</li>
<li>__rust_alloc_zeroed</li>
<li>__rust_realloc</li>
<li>__rust_dealloc</li>
<li>rust_oom</li>
<li>__rdl_oom</li>
</ul>
<hr>
<ul>
<li>rust_begin_unwind (deliberately unmangled to allow breakpoint placing)</li>
</ul>
<hr>
<ul>
<li>rust_panic</li>
<li>rust_eh_personality</li>
<li>__rust_start_panic</li>
<li>__rust_drop_panic</li>
<li>__rust_foreign_exception</li>
<li>__rust_panic_cleanup</li>
</ul>



<a name="247437438"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/upstreaming%20LLVM%20patch%20for%20__rust_%20alloc%20functions/near/247437438" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/upstreaming.20LLVM.20patch.20for.20__rust_.20alloc.20functions.html#247437438">(Jul 28 2021 at 09:14)</a>:</h4>
<p>so yeah I think we need mandatory mangling + using some other method to inform LLVM of any global allocator entry-points (such as custom attributes, that we could upstream later, and which could perhaps be usable from C or C++ through Clang custom attributes)</p>



<a name="247437665"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/upstreaming%20LLVM%20patch%20for%20__rust_%20alloc%20functions/near/247437665" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/upstreaming.20LLVM.20patch.20for.20__rust_.20alloc.20functions.html#247437665">(Jul 28 2021 at 09:17)</a>:</h4>
<p>I still think the allocator methods should stay this way. Mangling the panic related symbols (except <code>rust_begin_unwind</code>) is a good idea.</p>



<a name="247438234"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/upstreaming%20LLVM%20patch%20for%20__rust_%20alloc%20functions/near/247438234" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/upstreaming.20LLVM.20patch.20for.20__rust_.20alloc.20functions.html#247438234">(Jul 28 2021 at 09:24)</a>:</h4>
<p>even if we decide to stabilize them, I don't think they should look <em>anything</em> like C symbols</p>



<a name="247438268"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/upstreaming%20LLVM%20patch%20for%20__rust_%20alloc%20functions/near/247438268" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/upstreaming.20LLVM.20patch.20for.20__rust_.20alloc.20functions.html#247438268">(Jul 28 2021 at 09:25)</a>:</h4>
<p><em>and</em> they need to be versioned (whether tied to Rust version or not)</p>



<a name="247438389"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/upstreaming%20LLVM%20patch%20for%20__rust_%20alloc%20functions/near/247438389" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/upstreaming.20LLVM.20patch.20for.20__rust_.20alloc.20functions.html#247438389">(Jul 28 2021 at 09:26)</a>:</h4>
<p>to avoid backtraces looking terrible, one earlier idea of mine was using v0 mangling but with a special hashless crate root</p>



<a name="247438395"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/upstreaming%20LLVM%20patch%20for%20__rust_%20alloc%20functions/near/247438395" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/upstreaming.20LLVM.20patch.20for.20__rust_.20alloc.20functions.html#247438395">(Jul 28 2021 at 09:26)</a>:</h4>
<p><span class="user-mention silent" data-user-id="119009">eddyb</span> <a href="#narrow/stream/131828-t-compiler/topic/upstreaming.20LLVM.20patch.20for.20__rust_.20alloc.20functions/near/247438234">said</a>:</p>
<blockquote>
<p>even if we decide to stabilize them, I don't think they should look <em>anything</em> like C symbols</p>
</blockquote>
<p>If they don't, you can't call them from C.</p>



<a name="247438416"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/upstreaming%20LLVM%20patch%20for%20__rust_%20alloc%20functions/near/247438416" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/upstreaming.20LLVM.20patch.20for.20__rust_.20alloc.20functions.html#247438416">(Jul 28 2021 at 09:27)</a>:</h4>
<p>I mean they'd still be interfaceable with C, they should just not follow any existing naming conventions</p>



<a name="247438432"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/upstreaming%20LLVM%20patch%20for%20__rust_%20alloc%20functions/near/247438432" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/upstreaming.20LLVM.20patch.20for.20__rust_.20alloc.20functions.html#247438432">(Jul 28 2021 at 09:27)</a>:</h4>
<p><span class="user-mention silent" data-user-id="119009">eddyb</span> <a href="#narrow/stream/131828-t-compiler/topic/upstreaming.20LLVM.20patch.20for.20__rust_.20alloc.20functions/near/247438268">said</a>:</p>
<blockquote>
<p><em>and</em> they need to be versioned (whether tied to Rust version or not)</p>
</blockquote>
<p><code>alloc::Global</code> isn't versioned either.</p>



<a name="247438477"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/upstreaming%20LLVM%20patch%20for%20__rust_%20alloc%20functions/near/247438477" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/upstreaming.20LLVM.20patch.20for.20__rust_.20alloc.20functions.html#247438477">(Jul 28 2021 at 09:27)</a>:</h4>
<p><span class="user-mention silent" data-user-id="119009">eddyb</span> <a href="#narrow/stream/131828-t-compiler/topic/upstreaming.20LLVM.20patch.20for.20__rust_.20alloc.20functions/near/247438416">said</a>:</p>
<blockquote>
<p>I mean they'd still be interfaceable with C, they should just not follow any existing naming conventions</p>
</blockquote>
<p>In what way?</p>



<a name="247438506"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/upstreaming%20LLVM%20patch%20for%20__rust_%20alloc%20functions/near/247438506" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/upstreaming.20LLVM.20patch.20for.20__rust_.20alloc.20functions.html#247438506">(Jul 28 2021 at 09:28)</a>:</h4>
<p><span class="user-mention silent" data-user-id="119009">eddyb</span> <a href="#narrow/stream/131828-t-compiler/topic/upstreaming.20LLVM.20patch.20for.20__rust_.20alloc.20functions/near/247438389">said</a>:</p>
<blockquote>
<p>to avoid backtraces looking terrible, one earlier idea of mine was using v0 mangling but with a special hashless crate root</p>
</blockquote>
<p>this, for example</p>



<a name="247438575"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/upstreaming%20LLVM%20patch%20for%20__rust_%20alloc%20functions/near/247438575" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/upstreaming.20LLVM.20patch.20for.20__rust_.20alloc.20functions.html#247438575">(Jul 28 2021 at 09:28)</a>:</h4>
<p>I see. That would work I guess.</p>



<a name="247438577"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/upstreaming%20LLVM%20patch%20for%20__rust_%20alloc%20functions/near/247438577" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/upstreaming.20LLVM.20patch.20for.20__rust_.20alloc.20functions.html#247438577">(Jul 28 2021 at 09:28)</a>:</h4>
<p>e.g. <code>_RNvNtC4rust5alloc7realloc</code> would demangle as <code>rust::alloc::realloc</code></p>



<a name="247438729"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/upstreaming%20LLVM%20patch%20for%20__rust_%20alloc%20functions/near/247438729" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/upstreaming.20LLVM.20patch.20for.20__rust_.20alloc.20functions.html#247438729">(Jul 28 2021 at 09:30)</a>:</h4>
<p>and unlike a C-looking or C++-mangled symbol, it's <em>distinctly Rust</em></p>



<a name="247438950"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/upstreaming%20LLVM%20patch%20for%20__rust_%20alloc%20functions/near/247438950" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/upstreaming.20LLVM.20patch.20for.20__rust_.20alloc.20functions.html#247438950">(Jul 28 2021 at 09:33)</a>:</h4>
<p><span class="user-mention" data-user-id="133247">@bjorn3</span> the nice thing is that if we use "the symbol name of the declaration", <code>#[link_name = "..."]</code> is all it takes to "stabilize" any of them</p>



<a name="247439058"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/upstreaming%20LLVM%20patch%20for%20__rust_%20alloc%20functions/near/247439058" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/upstreaming.20LLVM.20patch.20for.20__rust_.20alloc.20functions.html#247439058">(Jul 28 2021 at 09:34)</a>:</h4>
<p>Almost, but not quite. The allocator methods are generated directly by the backend, not as part of any standard library crate.</p>



<a name="247444191"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/upstreaming%20LLVM%20patch%20for%20__rust_%20alloc%20functions/near/247444191" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/upstreaming.20LLVM.20patch.20for.20__rust_.20alloc.20functions.html#247444191">(Jul 28 2021 at 10:50)</a>:</h4>
<p>I wrote a Pre-RFC: <a href="https://hackmd.io/@bjorn3/B18MVoRR_">https://hackmd.io/@bjorn3/B18MVoRR_</a> <span class="user-mention" data-user-id="119009">@eddyb</span> do you have any feedback before I post it on i.r-l.o?</p>



<a name="247444439"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/upstreaming%20LLVM%20patch%20for%20__rust_%20alloc%20functions/near/247444439" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/upstreaming.20LLVM.20patch.20for.20__rust_.20alloc.20functions.html#247444439">(Jul 28 2021 at 10:54)</a>:</h4>
<p><span class="user-mention silent" data-user-id="133247">bjorn3</span> <a href="#narrow/stream/131828-t-compiler/topic/upstreaming.20LLVM.20patch.20for.20__rust_.20alloc.20functions/near/247439058">said</a>:</p>
<blockquote>
<p>Almost, but not quite. The allocator methods are generated directly by the backend, not as part of any standard library crate.</p>
</blockquote>
<p>they're still "imported" somewhere in <code>alloc</code>, so that could serve as the "source of truth"</p>



<a name="247444498"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/upstreaming%20LLVM%20patch%20for%20__rust_%20alloc%20functions/near/247444498" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/upstreaming.20LLVM.20patch.20for.20__rust_.20alloc.20functions.html#247444498">(Jul 28 2021 at 10:55)</a>:</h4>
<p>I guess so. There is currently no direction connection between the two though. <code>liballoc</code> simply uses <code>extern "C" { fn __rust_alloc(...</code> without a lang item.</p>



<a name="247444530"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/upstreaming%20LLVM%20patch%20for%20__rust_%20alloc%20functions/near/247444530" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/upstreaming.20LLVM.20patch.20for.20__rust_.20alloc.20functions.html#247444530">(Jul 28 2021 at 10:56)</a>:</h4>
<p>right, but that's trivially fixable</p>



<a name="247448169"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/upstreaming%20LLVM%20patch%20for%20__rust_%20alloc%20functions/near/247448169" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/upstreaming.20LLVM.20patch.20for.20__rust_.20alloc.20functions.html#247448169">(Jul 28 2021 at 11:44)</a>:</h4>
<p><a href="https://internals.rust-lang.org/t/pre-rfc-support-using-the-rust-allocator-from-c/15097">https://internals.rust-lang.org/t/pre-rfc-support-using-the-rust-allocator-from-c/15097</a></p>



<a name="247449692"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/upstreaming%20LLVM%20patch%20for%20__rust_%20alloc%20functions/near/247449692" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/upstreaming.20LLVM.20patch.20for.20__rust_.20alloc.20functions.html#247449692">(Jul 28 2021 at 12:03)</a>:</h4>
<p>oh no I didn't finish writing and sending my message, found this in Zulip:</p>
<blockquote>
<p>anyway, I have no feedback on the Pre-RFC, other that some kind of versioning might be desirable, tho most choices we might make for the names still allow to add some kind of extra information later - tho either way, stabilizing means that whatever usecases we allow have to always be supported (which, yes, as you've mentioned, would</p>
</blockquote>



<a name="247449957"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/upstreaming%20LLVM%20patch%20for%20__rust_%20alloc%20functions/near/247449957" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/upstreaming.20LLVM.20patch.20for.20__rust_.20alloc.20functions.html#247449957">(Jul 28 2021 at 12:06)</a>:</h4>
<p>not sure what I wanted to say more, I guess that while it would always be <em>possible</em> to support today's exact set of functions and ABI, we may not want that if we e.g. add another method to the trait, with a default implementation, that we do want to allow it being overriden by a global allocator, and which we'd proxy through the symbols that would be stabilized</p>



<a name="247449985"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/upstreaming%20LLVM%20patch%20for%20__rust_%20alloc%20functions/near/247449985" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/upstreaming.20LLVM.20patch.20for.20__rust_.20alloc.20functions.html#247449985">(Jul 28 2021 at 12:06)</a>:</h4>
<p>we couldn't do that if we promised C code could implement an allocator, because they'd be missing the function</p>



<a name="247450126"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/upstreaming%20LLVM%20patch%20for%20__rust_%20alloc%20functions/near/247450126" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/upstreaming.20LLVM.20patch.20for.20__rust_.20alloc.20functions.html#247450126">(Jul 28 2021 at 12:08)</a>:</h4>
<p><span class="user-mention silent" data-user-id="119009">eddyb</span> <a href="#narrow/stream/131828-t-compiler/topic/upstreaming.20LLVM.20patch.20for.20__rust_.20alloc.20functions/near/247449985">said</a>:</p>
<blockquote>
<p>we couldn't do that if we promised C code could implement an allocator, because they'd be missing the function</p>
</blockquote>
<p>Promising this would require more than my Pre-RFC as currently there is no way to tell rustc that you wrote a global allocator without actually defining it at the same place, so rustc will either error out due to no global allocator existing in it's view or try to generate an allocator shim for libstd's default allocator.</p>



<a name="247488374"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/upstreaming%20LLVM%20patch%20for%20__rust_%20alloc%20functions/near/247488374" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/upstreaming.20LLVM.20patch.20for.20__rust_.20alloc.20functions.html#247488374">(Jul 28 2021 at 17:16)</a>:</h4>
<p>instead of upstreaming rust details, could LLVM get a new API for registering allocator details?</p>



<a name="247495312"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/upstreaming%20LLVM%20patch%20for%20__rust_%20alloc%20functions/near/247495312" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> durin42 <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/upstreaming.20LLVM.20patch.20for.20__rust_.20alloc.20functions.html#247495312">(Jul 28 2021 at 18:07)</a>:</h4>
<p>That's probably worth discussing with upstream. I'm happy to try and shake a tree on my side and see if there's anyone from our stable of LLVM hackers that would be interested in having the conversation. Let me know?</p>



<a name="247499311"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/upstreaming%20LLVM%20patch%20for%20__rust_%20alloc%20functions/near/247499311" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/upstreaming.20LLVM.20patch.20for.20__rust_.20alloc.20functions.html#247499311">(Jul 28 2021 at 18:38)</a>:</h4>
<p>just to be clear, "registering" might not be necessary if we can have attributes/metadata instead, to annotate functions directly</p>



<a name="247499371"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/upstreaming%20LLVM%20patch%20for%20__rust_%20alloc%20functions/near/247499371" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/upstreaming.20LLVM.20patch.20for.20__rust_.20alloc.20functions.html#247499371">(Jul 28 2021 at 18:38)</a>:</h4>
<p>idk how willing LLVM is to retire their hacky symbol hardcoding practices</p>



<a name="247501269"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/upstreaming%20LLVM%20patch%20for%20__rust_%20alloc%20functions/near/247501269" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> durin42 <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/upstreaming.20LLVM.20patch.20for.20__rust_.20alloc.20functions.html#247501269">(Jul 28 2021 at 18:52)</a>:</h4>
<p>I'll try and shake a tree and see if they're willing to consider something.</p>



<a name="247502936"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/upstreaming%20LLVM%20patch%20for%20__rust_%20alloc%20functions/near/247502936" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/upstreaming.20LLVM.20patch.20for.20__rust_.20alloc.20functions.html#247502936">(Jul 28 2021 at 19:04)</a>:</h4>
<p>I recall there being some effort around making allocation optimization agnostic to specific symbol names.</p>



<a name="247502956"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/upstreaming%20LLVM%20patch%20for%20__rust_%20alloc%20functions/near/247502956" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/upstreaming.20LLVM.20patch.20for.20__rust_.20alloc.20functions.html#247502956">(Jul 28 2021 at 19:04)</a>:</h4>
<p>not sure where it was, but there was definitely some discussion about that before.</p>



<a name="247503016"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/upstreaming%20LLVM%20patch%20for%20__rust_%20alloc%20functions/near/247503016" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/upstreaming.20LLVM.20patch.20for.20__rust_.20alloc.20functions.html#247503016">(Jul 28 2021 at 19:04)</a>:</h4>
<p>and yes, I believe it was a metadata annotation on the declaration or somesuch.</p>



<a name="247503289"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/upstreaming%20LLVM%20patch%20for%20__rust_%20alloc%20functions/near/247503289" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/upstreaming.20LLVM.20patch.20for.20__rust_.20alloc.20functions.html#247503289">(Jul 28 2021 at 19:07)</a>:</h4>
<p>Similar to GCC's <code>__attribute((malloc))</code>?</p>



<a name="247503646"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/upstreaming%20LLVM%20patch%20for%20__rust_%20alloc%20functions/near/247503646" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/upstreaming.20LLVM.20patch.20for.20__rust_.20alloc.20functions.html#247503646">(Jul 28 2021 at 19:09)</a>:</h4>
<p>Sort of. I don't know offhand if there are other requirements imposed by LLVM for allocation functions than just no-aliases.</p>



<a name="247602894"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/upstreaming%20LLVM%20patch%20for%20__rust_%20alloc%20functions/near/247602894" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> durin42 <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/upstreaming.20LLVM.20patch.20for.20__rust_.20alloc.20functions.html#247602894">(Jul 29 2021 at 15:54)</a>:</h4>
<p>So, my LLVM experts say it's plausible that we could implement more attributes in LLVM, and thread that through. I might give that a shot.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>